#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream>

bool MyCompare(const std::string& a, const std::string& b) {
    if (a.size() != b.size()) {
        return a.size() < b.size();
    }

    int oneCountA = 0;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] == '1') {
            oneCountA++;
        }
    }

    int oneCountB = 0;
    for (int i = 0; i < b.size(); i++) {
        if (b[i] == '1') {
            oneCountB++;
        }
    }

    if (oneCountA != oneCountB) {
        return oneCountA < oneCountB;
    }

    return a < b;


}


/**
 * 
 * 时间复杂度：O(nlogn * 256)
 * 空间复杂度：O(256 * n)
 * 
 * 01串排序
 *
 * @return 
 */
int main() {

    std::string arr[110]{};

    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        std::cin >> arr[i];
    }

    std::sort(arr, arr + n, MyCompare);

    for(int i = 0; i < n; i++) {
        printf("%s\n", arr[i].c_str());
    }


    return 0;
}